package com.cwh.taskcenter.domain.task.model;

import com.alibaba.cola.domain.Entity;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * @author cwh
 */
@Data
@Entity
public class UserTask {

    /**
     * 用户任务ID
     */
    private Long id;

    /**
     * 用户ID
     */
    private Long userId;

    /**
     * 任务模板ID
     */
    private Long taskId;

    /**
     * 状态(1:未开始,2:进行中,3:已完成)
     */
    private String userTaskStatus;

    /**
     * 当前进度
     */
    private Integer progress;

    /**
     * 完成时间
     */
    private LocalDateTime completeTime;

    /**
     * 创建时间
     */
    private LocalDateTime createdAt;

    /**
     *  更新时间
     */
    private LocalDateTime updatedAt;


    public void updateProgress(Integer progress) {
        if (Objects.equals(userTaskStatus, UserTaskStatus.NOT_STARTED.name())) {
            this.userTaskStatus = UserTaskStatus.IN_PROGRESS.name();
        }

        if (Objects.equals(progress,100)) {
            this.userTaskStatus = UserTaskStatus.COMPLETED.name();
            this.completeTime = LocalDateTime.now();
        }
        this.progress = progress;
        this.updatedAt = LocalDateTime.now();
    }

}
